package com.api.core.exception;

import com.api.core.model.ResponseModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.ValidationException;

/**
 * 全局移除捕获
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

	@ResponseBody
	@ExceptionHandler(value = ValidationException.class)
	public ResponseModel validationExceptionHandler(ValidationException exception) {
		String msg= exception.getMessage();
		log.error("one-全局异常处理-"+msg);
		return new ResponseModel(-1,msg);
	}
	
	
	@ResponseBody
	@ExceptionHandler(value = CodeBoxException.class)
	public ResponseModel codeBoxExceptionclassHandler(CodeBoxException exception) {
		String msg= exception.getMsg();
		log.error("tow-全局异常处理-"+msg);
		return new ResponseModel(exception.getCode(),msg);
	}

}
